package com.hyt.it.ogt.controller.ykcj.exam;

import java.util.List;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.hyt.it.ogt.controller.base.BaseController;
import com.hyt.it.ogt.ykcj.common.constant.HttpStatus;
import com.hyt.it.ogt.ykcj.common.core.domain.AjaxResult;
import com.hyt.it.ogt.ykcj.common.exception.CustomException;
import com.hyt.it.ogt.ykcj.feign.model.Classification;
import com.hyt.it.ogt.ykcj.service.exam.IClassificationService;
import com.hyt.loginfo.service.IBaseLoginService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import io.swagger.annotations.ApiSort;

/**
 * description
 *
 * @author yaojian
 * @createTime 2022/02/14
 */
@Api(tags = "Classification.18.考试分类类", value = "考试分类类")
@ApiSort(value = 213)
@RestController
@RequestMapping("/exam/classification")
public class ClassificationController extends BaseController {

    @Autowired
    private IClassificationService classificationService;
    @Autowired
    private IBaseLoginService baseLoginService;

    /**
     * 获取分类树
     */
    @ApiOperation("获取分类树")
    @ApiResponses({
            @ApiResponse(code = HttpStatus.SUCCESS, message = "OK", response = Classification.class),
    })
    @GetMapping(value = "/getClassificationTree/{other}")
    public AjaxResult getClassificationTree(@PathVariable("other") String other) {
        List<Classification> classificationTree = classificationService.getClassificationTree(other);
        return AjaxResult.success(classificationTree);
    }

    /**
     * 获取分类列表
     */
    @ApiOperation("获取分类列表")
    @ApiResponses({
            @ApiResponse(code = HttpStatus.SUCCESS, message = "OK", response = Classification.class),
    })
    @GetMapping(value = "/getClassificationList")
    public AjaxResult getClassificationList() {
        List<Classification> classificationTree = classificationService.getClassificationList();
        return AjaxResult.success(classificationTree);
    }

    /**
     * 根据id获取当前及子节点的id
     * (这个接口有问题)
     */
    @ApiOperation("根据id获取当前及子节点的id")
    @ApiResponses({
            @ApiResponse(code = HttpStatus.SUCCESS, message = "OK", response = Classification.class),
    })
    @GetMapping(value = "/getStringListById/{id}")
    public AjaxResult getStringListById(@PathVariable("id") String id) {
        if (StringUtils.isEmpty(id)){
            throw new CustomException("id不能为空");
        }
        List<Classification> classificationList = classificationService.getClassificationList();
        List<String> strings = classificationService.getChildrenId(id,classificationList);
        return AjaxResult.success(strings);
    }

    /**
     * 根据id获取当前及子节点的id
     */
    @ApiOperation("根据id获取当前及子节点的id")
    @ApiResponses({
            @ApiResponse(code = HttpStatus.SUCCESS, message = "OK", response = Classification.class),
    })
    @GetMapping(value = "/getClassificationListById/{id}")
    public AjaxResult getClassificationListById(@PathVariable("id") String id) {
        if (StringUtils.isEmpty(id)){
            throw new CustomException("id不能为空");
        }
        List<Classification> classificationTree = classificationService.getChildList(id);
        return AjaxResult.success(classificationTree);
    }

    /**
     * 根据id获取当前及子节点的id
     */
    @ApiOperation("获取存在节点分类树")
    @ApiResponses({
            @ApiResponse(code = HttpStatus.SUCCESS, message = "OK", response = Classification.class),
    })
    @GetMapping(value = "/getHasNodeTree")
    public AjaxResult getHasNodeTree() {
        String officeId = baseLoginService.getOfficeId();
        List<Classification> classificationTree = classificationService.getHasNodeTree(officeId);
        return AjaxResult.success(classificationTree);
    }
}
